#include "common.hpp"

int main()
{
    std::cout << "I am server" << std::endl;

    fifo named_pipe(PATH);
    int rfd = open(PATH, O_RDONLY);
    
    char buffer[1024] = {0};
    while (1)
    {
        int n = read(rfd, buffer, sizeof(buffer) - 1);
        if (0 == n)
        {
            std::cout << "client exit, server also exit" << std::endl;
            break;
        }
        else if (-1 == n)
        {
            std::cerr << "read error, " << "errno: " << errno << ", errorstring: " << strerror(errno) << std::endl;
            exit(-1);
        }
        else
        {
            buffer[n] = 0;
            std::cout << buffer << std::endl;
        }
    }

    close(rfd);
    return 0;
}